package ebcs.plat.trans.base;

import jplat.core.trans.JTransContext;
import jplat.tools.string.DateUtil;
import jplat.tools.string.JRandomUtil;

import org.apache.log4j.Logger;

import ebcs.plat.icop.connect.ICOPConnector;

/***
 * @author zhangcq
 * @date Nov 28, 2016
 * @comment 长行E钱庄服务端通讯基础类V1,支持ICOP通讯 
 */
public abstract class BCSTransBaseV1
{
	private Logger logger = Logger.getLogger(BCSTransBaseV1.class);
	
	//E钱庄默认接入渠道号
	private static String __CHNL_ID_EBK = "104";
	
	//E钱庄老渠道.
	private static String __CHNL_ID_OEBK = "MB_01";
	//E钱庄老渠道.
	private static String __CHNL_ID_ESHOP = "113";
	//密码类型.
	private static String __ENCRYPTTYPE = "4";
	
	/**
	 * 初始化上线文.
	 * @author zhangcq
	 * @date Dec 13, 2016
	 * @comment 
	 * @param context
	 * @return
	 */
	protected boolean initTransContextV1( JTransContext context )
	{
		//流水.
		context.putValue(ICOPConnector.khSEQNO, DateUtil.todayStr(DateUtil.FMT_ALL)+JRandomUtil.randomInt(6));
		
//		context.putValue(ICOPConnector.khUUID, "");
		//渠道.
		context.putValue(ICOPConnector.khCHANNEL_ID,__CHNL_ID_EBK );
		
//		context.putValue(ICOPConnector.khENC_TYPE, "");
//		context.putValue(ICOPConnector.khTERM_NO, "");
//		context.putValue(ICOPConnector.khBRANCH_ID, "");
//		context.putValue(ICOPConnector.khOPER_ID, "");
		
		return true;
	}
	/**
	 * 初始化上线文.
	 * @author zhangcq
	 * @date Dec 13, 2016
	 * @comment 
	 * @param context
	 * @return
	 */
	protected boolean initTransContextV2( JTransContext context )
	{
		//流水.
		context.putValue(ICOPConnector.khSEQNO, DateUtil.todayStr(DateUtil.FMT_ALL)+JRandomUtil.randomInt(6));
//		context.putValue(ICOPConnector.khUUID, "");
		//渠道.
		context.putValue(ICOPConnector.khCHANNEL_ID,__CHNL_ID_ESHOP );

		
		
		context.putValue(ICOPConnector.khENC_TYPE, "2");
//		context.putValue(ICOPConnector.khTERM_NO, "");
//		context.putValue(ICOPConnector.khBRANCH_ID, "");
//		context.putValue(ICOPConnector.khOPER_ID, "");
		
		return true;
	}
	/**
	 * 初始化上线文.
	 * @author zhangcq
	 * @date Dec 13, 2016
	 * @comment 
	 * @param context
	 * @return
	 */
	protected boolean initTransContextV3( JTransContext context )
	{
		//流水.
		context.putValue(ICOPConnector.khSEQNO, DateUtil.todayStr(DateUtil.FMT_ALL)+JRandomUtil.randomInt(6));
//		context.putValue(ICOPConnector.khUUID, "");
		//渠道.
		context.putValue(ICOPConnector.khCHANNEL_ID,__CHNL_ID_ESHOP );

		
		
		//context.putValue(ICOPConnector.khENC_TYPE, "2");
//		context.putValue(ICOPConnector.khTERM_NO, "");
//		context.putValue(ICOPConnector.khBRANCH_ID, "");
//		context.putValue(ICOPConnector.khOPER_ID, "");
		
		return true;
	}
	
	/**
	 * 初始化上线文.
	 * @author zhangcq
	 * @date Dec 13, 2016
	 * @comment 
	 * @param context
	 * @return
	 */
	protected boolean initTransContextV4( JTransContext context )
	{
		//流水.
		context.putValue(ICOPConnector.khSEQNO, DateUtil.todayStr(DateUtil.FMT_ALL)+JRandomUtil.randomInt(6));
//		context.putValue(ICOPConnector.khUUID, "");
		//渠道.
		context.putValue(ICOPConnector.khCHANNEL_ID,__CHNL_ID_ESHOP );

		
		
		context.putValue(ICOPConnector.khENC_TYPE, "4");
//		context.putValue(ICOPConnector.khTERM_NO, "");
//		context.putValue(ICOPConnector.khBRANCH_ID, "");
//		context.putValue(ICOPConnector.khOPER_ID, "");
		
		return true;
	}
	/**
	 * 老渠道初始化.
	 * @author zhangcq
	 * @date Dec 13, 2016
	 * @comment 
	 * @param context
	 * @return
	 */
	protected boolean initTransContextV0( JTransContext context )
	{
		//流水.
		context.putValue(ICOPConnector.khSEQNO, DateUtil.todayStr(DateUtil.FMT_ALL)+JRandomUtil.randomInt(6));
		
//		context.putValue(ICOPConnector.khUUID, "");
		//渠道.
		context.putValue(ICOPConnector.khCHANNEL_ID,__CHNL_ID_OEBK );
		
//		context.putValue(ICOPConnector.khENC_TYPE, "");
//		context.putValue(ICOPConnector.khTERM_NO, "");
//		context.putValue(ICOPConnector.khBRANCH_ID, "");
//		context.putValue(ICOPConnector.khOPER_ID, "");
		
		return true;
	}
	
	/**
	 * 发送ICOP交易数据.
	 * @author zhangcq
	 * @date Dec 13, 2016
	 * @comment 
	 * @param context
	 * @return
	 */
	protected boolean doTrans( JTransContext context )
	{
		//发送渠道交易请求.
		if ( !ICOPConnector.sendICOPMessage(context) )
		{
			return false;
		}
		
		return true;
	}

}
